const baseURL = 'http://dev.bjywkd.com:10022'

/**
 * api 服务异常
 */
class APTError {
  constructor(code, msg) {
    this.code = code;
    this.msg = msg;
  }
}

/**
 * webbt configer
 */
class WebbtConfigerAPI {
  constructor() {

    this.url = baseURL + '/webbt/configer';
  }

  generateUrl(extraPath = '') {
    if (!this.url) {
      throw new APIError(-1, 'api 方法没有定义url!');
    }
    let queryUrl = '';
    if (extraPath) {
      extraPath = '' + extraPath;
      extraPath = extraPath.startsWith('/') ? extraPath.slice(1) : extraPath;
      queryUrl = this.url + '/' + extraPath;
    } else {
      queryUrl = this.url;
    }
    return queryUrl;
  }

  get(query = {}, onSuccess = $.noop, onFail = $.noop) {
    const queryUrl = this.generateUrl();
    console.log(`>>> Get Few url: ${queryUrl}`);
    $.ajax({
      url: queryUrl,
      type: 'GET',
      data: query,
      success: function (res) {
        onSuccess(res);
      },
      error: function (error) {
        onFail(error);
      }
    });
  }
}

const innerServices = {
  webbtConfigerAPI: new WebbtConfigerAPI(),
}
